package java6681.lesson10;

import java.util.Arrays;
import java.util.Scanner;

//-10.8 5.9 6 2.1
public class MathExercise6681 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请用空格分隔输入mix、max、x1、x2");
        double min = sc.nextDouble();
        double max = sc.nextDouble();
        double x1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        int[] num = getAnswer6681(min, max, x1, x2);
        if (num == null) {
            System.out.println("题目没有意义!");
        } else {
            System.out.println("在" + min + "到" + max + "之间，绝对值大于" + x1
                    + "或者小于" + x2 + "的整数有" + num.length + "个：");
            System.out.println(Arrays.toString(num));
        }

    }

    public static int[] getAnswer6681(double min, double max, double x1, double x2) {
        int k = 0;
        int start = (int) Math.ceil(min);
        int end = (int) Math.ceil(max);
        if (end - start + 1 < 0 || x1 < 0 || x2 < 0 || x1 < x2) {
            return null;
        }
        int[] intArray = new int[end - start + 1];
        for (int i = start; i < end; i++) {
            if (Math.abs(i) > x1 || Math.abs(i) < x2) {
                intArray[k++] = i;
            }
        }
        return Arrays.copyOfRange(intArray, 0, k);
    }
}
